import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { getConfig } from './utils';
import { AuthModule } from './auth/auth.module';
import { JwtModule } from '@nestjs/jwt';
import { CityModule } from './city/city.module';
import { ScenicSpotModule } from './scenic-spot/scenic-spot.module';
import { PostModule } from './post/post.module';
import { CommentModule } from './comment/comment.module';
import { UserLikeModule } from './user-like/user-like.module';
import { UserFavoriteModule } from './user-favorite/user-favorite.module';
import { ImageModule } from './image/image.module';
import { UploadModule } from './upload/upload.module';
@Module({
  imports: [
     JwtModule.register({
      secret: 'jwt-key',
      signOptions: { expiresIn: '24h' },
    }),
    ConfigModule.forRoot({
      ignoreEnvFile: true,
      isGlobal: true,
      load: [getConfig],
    }),
    // TypeOrmModule.forRoot({
    //   type: 'mysql',
    //   host: 'localhost',
    //   port: 3306,
    //   username: 'root',
    //   password: 'rootroot',
    //   database: 'nestjs',
    //   entities: [__dirname + '/**/*.entity{.ts,.js}'],
    //   synchronize: true,
    // }),
    TypeOrmModule.forRootAsync({
      useFactory: async (config: ConfigService) => {
        return {
          ...config.get('MYSQL_CONFIG'),
          entities: [__dirname + '/**/*.entity{.ts,.js}'],
        };
      },
      inject: [ConfigService],
    }),
    UserModule,
    AuthModule,
    CityModule,
    ScenicSpotModule,
    PostModule,
    CommentModule,
    UserLikeModule,
    UserFavoriteModule,
    ImageModule,
    UploadModule,
  ],
  controllers: [AppController], // 处理http请求 路由控制 向客户端返回响应
  providers: [AppService], // 处理业务逻辑  各个模块之间可以共享 服务提供者
  exports: [], // 导出服务的列表
})
export class AppModule {}
